package com.lanou.bookstore.book.service;

import com.lanou.bookstore.book.dao.BookDao;
import com.lanou.bookstore.book.domain.Book;

import java.sql.SQLException;
import java.util.List;

public class BookService {
    private BookDao bookDao = new BookDao();

    public List<Book> findAll() {
        List<Book> bookList = null;
        try {
            bookList = bookDao.findAll();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return bookList;
    }

    public List<Book> findByCid(String cid) {
        List<Book> bookList = null;
        try {
            bookList = bookDao.findByCid(cid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return bookList;
    }

    public Book load(String bid) {
        Book book = null;
        try {
            book = bookDao.findByBid(bid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return book;
    }

    public Book findByBid(String bid) {
        Book book = null;
        try {
            book = bookDao.findByBid(bid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return book;
    }

    public void updateDelByBid(Integer bid) {
        try {
            bookDao.updataDelByBid(bid);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void updateAll(Book book) {
        try {
            bookDao.updateAll(book);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public void addBook(Book book) {
        try {
            bookDao.addBook(book);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
